<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>倒计时</title>
  </head>
  <body>
    <h1></h1>
  </body>
  <script>
    var h1 = document.querySelector("h1");
    var date = new Date();
    var dateEnd = new Date("2021/2/20 00:00:00");
    console.log(date.getTime(), dateEnd.getTime());
    var t = dateEnd.getTime() - date.getTime();
    var tT = Math.floor(t / 1000 / 60 / 60 / 24);
    var sT = Math.floor(t / 1000 / 60 / 60) % 24;
    var fT = Math.floor(t / 1000 / 60) % 60;
    var mT = Math.floor(t / 1000) % 60;
    var html = `距离新年还有${tT}天${sT}小时${fT}分钟${mT}秒`;
    h1.innerText = html;
  </script>
</html>
